/*****************************************************\
* Copyright (c) 2020 The game2d Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.

* Author:         dzlua - https://gitee.com/dzlua/game2d.git
* Email:          505544956@qq.com
* FileName:       ctrls/layout.hpp
* Create Time:    2020/03/19 19:09:28
* Description:    /
\****************************************************/
#ifndef __GAME2D_CTRLS_LAYOUT_H__
#define __GAME2D_CTRLS_LAYOUT_H__

#include "control.h"

namespace g2d {
namespace ctrl {
  class Layout : public Control {
      friend class UserInterface;
    public:
      Layout(bool load_res_on_enter);
      virtual ~Layout() = default;
    public:
      virtual const Inset& inset() const;
      virtual void set_inset(const Inset &inset);
    public:
      virtual void set_attribute(const char *name, const char *value);
    protected:
      virtual void update_control(Input &inp, Audio &aud) override;
      virtual void update_layout() override;
    protected:
      Inset inset_;
  };

  class HorLayout : public Layout {
    public:
      HorLayout(bool load_res_on_enter);
      virtual ~HorLayout() = default;
    public:
      virtual float padding() const;
      virtual void set_padding(float padding);
      virtual VerAlign align() const;
      virtual void set_align(VerAlign align);
    public:
      virtual void set_attribute(const char *name, const char *value) override;
      virtual void update_layout() override;
    protected:
      VerAlign valign_;
      float hpadding_;
  };

  class VerLayout : public Layout {
    public:
      VerLayout(bool load_res_on_enter);
      virtual ~VerLayout() = default;
    public:
      virtual float padding() const;
      virtual void set_padding(float padding);
      virtual HorAlign align() const;
      virtual void set_align(HorAlign align);
    public:
      virtual void set_attribute(const char *name, const char *value) override;
      virtual void update_layout() override;
    protected:
      HorAlign halign_;
      float vpadding_;
  };

  class TileLayout : public Layout {
    public:
      TileLayout(bool load_res_on_enter);
      virtual ~TileLayout() = default;
    public:
      virtual float hpadding() const;
      virtual void set_hpadding(float padding);
      virtual float vpadding() const;
      virtual void set_vpadding(float padding);

      virtual void set_item_size(const Size &size);
      virtual const Size& item_size() const;
      virtual Uint32 column() const;
      virtual void set_column(Uint32 cols);
    public:
      virtual void set_attribute(const char *name, const char *value) override;
      virtual void update_layout() override;
    protected:
      float hpadding_;
      float vpadding_;
      Uint32 cols_;
      Size item_size_;
  };

  class TabLayout : public Layout {
    public:
      TabLayout(bool load_res_on_enter);
      virtual ~TabLayout() = default;
    public:
      virtual Uint32 selected_id() const;
      virtual Control* selected_ctrl() const;
      virtual void select_item(Control *ctrl);
      virtual void select_item(Uint32 idx);
    public:
      virtual void set_attribute(const char *name, const char *value) override;
      virtual void update_layout() override;
    protected:
      Uint32 sel_;
  };
} // end namespace ctrl
} // end namespace g2d

#endif // __GAME2D_CTRLS_LAYOUT_H__